
#include "stripper.h"



stripper::stripper(): m_tagIsFound(false), //
                      m_outputStatus(stripper::UNDEFINED){

  // actually do nothing
}

std::string stripper::strip( std::string line, std::string tag, stripper::stripMode direction ) {

  std::string result="";
  m_tagIsFound = false;

  // check strip mode
  if ( direction != FRONT && direction != BACK ) {
    m_outputStatus = stripper::WRONG_DIRECTION;
    return result;
  }



  if ( !line.empty() ) {

    // it is really very important that found is of type size_t
    //   if type was unsigned int, then problems arise using libraries 
    //    which defines their own types, and re-define normal types (eg: ROOT), 
    //   even if the STL defines size_t as a typedef for unsigned int
    size_t found = line.find( tag ) ;
    if ( found != std::string::npos ) {

      m_tagIsFound = true;
      // front-mode
      if ( direction==FRONT ) {
        result = line.substr( 0, found);
        m_outputStatus = stripper::FRONT_DIRECTION;
      }

      // back-mode: do not hit the end of the string when doing this
      else if ( direction==BACK && found+tag.size()<line.size() ) {
        result = line.substr( found+tag.size(), std::string::npos );
        m_outputStatus = stripper::BACK_DIRECTION;
      }

    } // if tag is found
  } // non-empty input string

  else {
    m_outputStatus = stripper::EMPTY_INPUT;
  }

  return result;
}


